// util2.js - uni-app 适用版
class ApiService {
	constructor(baseURL = '') {
		this.baseURL = baseURL;
	}

	send({
		url,
		method = 'GET',
		data = {},
		header = {}
	}) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: this.baseURL + url,
				method,
				data,
				header: {
					'Content-Type': 'application/json'
				},
				success: (res) => {
					// if (res.statusCode === 200) {
					// 	resolve(res.data.data ?? res.data);
					// } else {
					// 	reject(res.data?.message || '请求失败');
					// }
					resolve("Success-Success")
				},
				fail: (err) => reject(err.errMsg || '网络错误')
			});
		});
	}

	get(url, params = {}, header = {}) {
		return this.send({
			url,
			method: 'GET',
			data: params,
			header
		});
	}

	post(url, data = {}, header = {}) {
		return this.send({
			url,
			method: 'POST',
			data,
			header
		});
	}
}

// 建议把 baseURL 放 config 里
const apiService = new ApiService('https://api.xxx.com');
export default apiService;